﻿using System;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;

namespace UnityGameUI
{
	// Token: 0x0200000A RID: 10
	internal class WindowDragHandler : MonoBehaviour
	{
		// Token: 0x0600003A RID: 58 RVA: 0x00003DCA File Offset: 0x00001FCA
		public WindowDragHandler()
		{
			WindowDragHandler.instance = this;
		}

		// Token: 0x0600003B RID: 59 RVA: 0x00003DD8 File Offset: 0x00001FD8
		public void Awake()
		{
			WindowDragHandler.rectTransform = base.gameObject.GetComponent<RectTransform>();
		}

		// Token: 0x0600003C RID: 60 RVA: 0x00003DEA File Offset: 0x00001FEA
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EventTrigger), "OnBeginDrag")]
		public static void OnBeginDrag(PointerEventData eventData)
		{
			if (WindowDragHandler.pointerId != -98456)
			{
				eventData.pointerDrag = null;
				return;
			}
			WindowDragHandler.pointerId = eventData.pointerId;
			RectTransformUtility.ScreenPointToLocalPointInRectangle(WindowDragHandler.rectTransform, eventData.position, Camera.current, out WindowDragHandler.initialTouchPos);
		}

		// Token: 0x0600003D RID: 61 RVA: 0x00003E28 File Offset: 0x00002028
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EventTrigger), "OnDrag")]
		public static void OnDrag(PointerEventData eventData)
		{
			if (eventData.pointerId != WindowDragHandler.pointerId)
			{
				return;
			}
			Vector2 touchPos;
			RectTransformUtility.ScreenPointToLocalPointInRectangle(WindowDragHandler.rectTransform, eventData.position, Camera.current, out touchPos);
			Vector2 tmp = touchPos - WindowDragHandler.initialTouchPos;
			WindowDragHandler.rectTransform.gameObject.transform.position += new Vector3(tmp.x, tmp.y, Camera.current.nearClipPlane);
		}

		// Token: 0x0600003E RID: 62 RVA: 0x00003EA1 File Offset: 0x000020A1
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EventTrigger), "OnEndDrag")]
		public static void OnEndDrag(PointerEventData eventData)
		{
			if (eventData.pointerId != WindowDragHandler.pointerId)
			{
				return;
			}
			WindowDragHandler.pointerId = -98456;
		}

		// Token: 0x04000017 RID: 23
		public static WindowDragHandler instance;

		// Token: 0x04000018 RID: 24
		private const int NON_EXISTING_TOUCH = -98456;

		// Token: 0x04000019 RID: 25
		private static RectTransform rectTransform;

		// Token: 0x0400001A RID: 26
		private static int pointerId = -98456;

		// Token: 0x0400001B RID: 27
		private static Vector2 initialTouchPos;
	}
}
